// pages/home/pages/party5/party5.js
var r = require('../../../../utils/request.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type: 0, //分类

    list: [],
    page: 1,
    pages: 0,
    // list:[
    //   {id:1,title:'活动室201',status:0,time:'2021-08-20 12:00-20:00'},
    //   {id:2,title:'活动室202',status:1,time:'2021-08-20 12:00-20:00'},
    //   {id:3,title:'活动室203',status:2,time:'2021-08-20 12:00-20:00'},
    // ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  //加载数据列表
  datalist(pageNo) {
    this.loading = true
    wx.showLoading()

    let url = '/activityroom/roomList'
    if(this.data.type == 1){
      url = '/activityroomApply/roomApplyUser'
    }
    var param = {
      userId:wx.getStorageSync('userId'),
      page: pageNo,
      limit: 10
    };
    //获取数据列表
    r.toGet(url, param, (res) => {
      this.loading = false
      wx.hideLoading()
      if (!res.retData || !res.retData.records || res.retData.records.length == 0) {
        wx.showToast({
          title: '暂无活动室',
          icon:'none'
        })
        return
      } else {
        this.setData({
          page: pageNo, //当前的页号
          pages: res.retData.pages, //总页数
          list: this.data.list.concat(res.retData.records)
        })
      }
    })
  }, 

  //当前日期
  getDate() { 
    var that = this;
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    if (month < 10) {
      month = "0" + month;
    }
    if (day < 10) {
      day = "0" + day;
    }
    var nowDate = year + "-" + month + "-" + day;

    return nowDate;
  },

  // 详情
  detail(e){
    let id = e.currentTarget.dataset.id
    let time = this.getDate()
    wx.navigateTo({
      url: '../party5Detail/party5Detail?id='+id+'&time='+time,
    })
  },

  detail2(e){
    let id = e.currentTarget.dataset.id
    let status = e.currentTarget.dataset.status
    let time = e.currentTarget.dataset.time.split(' ')[0]
    // console.log(time)
   
    // 未通过
    if(status == 2){
      wx.navigateTo({
        url: '../party5Refuse/party5Refuse?id='+id,
      })
    }else{
      wx.navigateTo({
        url: '../party5Detail2/party5Detail2?id='+id+'&time='+time
      })
    }
  },

  // 切换
  tabs(e) {
    let num = e.currentTarget.dataset.num
    this.setData({
      type: num,
      page: 1,
      pages: 0,
      list: []
    })
    this.datalist(1);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      page: 1,
      pages: 0,
      list: []
    })
    this.datalist(1);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (!this.loading && this.data.page < this.data.pages) {
      this.datalist(this.data.page + 1)
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})